home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / giochi / aboulder.lha / ABoulderDash1.0 / calculate.s < prev    next >
Text File  |  1995-08-27  |  26KB  |  1,142 lines

  1.     opt    L+
  2.     opt    O2+
  3.     opt    OW-
  4.  
  5. *==========================================
  6. *
  7. * File:        Calculate.s
  8. * Version:     1
  9. * Revision:    0
  10. * Created:     5-VII-1993
  11. * By:          FNC Slothouber
  12. * Last Update: 22-Jan-1995
  13. * By:          FNC Slothouber
  14. *
  15. *==========================================
  16.  
  17.     incdir    "include:"
  18.  
  19.     include    boulderdash.i
  20.  
  21.     XDEF    Calculate
  22.  
  23.     XREF    ted_bitmap_x
  24.     XREF    ted_grid_field_x
  25.     XREF    animate_offset_x
  26.     XREF    ted_bitmap_y
  27.     XREF    ted_grid_field_y
  28.     XREF    animate_offset_y
  29.     XREF    flag_scroll_left
  30.     XREF    flag_scroll_right
  31.     XREF    flag_view_scroll_left
  32.     XREF    flag_view_scroll_right
  33.     XREF    flag_scroll_up
  34.     XREF    flag_scroll_down
  35.     XREF    flag_view_scroll_up
  36.     XREF    flag_view_scroll_down
  37.     XREF    Update_Score
  38.     XREF    time_flag
  39.     XREF    ted_wins_flag
  40.     XREF    ted_reach_limit
  41.  
  42.     XDEF    test_fungis
  43.     XDEF    fungis_timer
  44.  
  45. MAX_FUN_TIME    equ    500
  46.  
  47.  
  48. MTry_Move_Left    macro
  49.     cmp.w    #G_EMPTY,grid_type+ONE_LEFT(a2)
  50.     bne.s    .\@
  51.     cmp.b    #EMPTY_REAL_EMPTY,grid_data+ONE_LEFT(a2)
  52. *    bne.s    .\@
  53.     bne    .next
  54.     move.w    #TRANS_MOVER_LEFT,grid_trans(a2)
  55.     move.w    #DRAW_MOVER_LEFT0,grid_draw(a2)
  56.     move.w    #DRAW_NOT,grid_draw+ONE_LEFT(a2)
  57.     move.b    #4,grid_dirty(a2)
  58.     move.b    #MOVING_LEFT,grid_data(a2)
  59.     move.b    #EMPTY_OCC_MOVER,grid_data+ONE_LEFT(a2)
  60.     bra    .next
  61. .\@
  62.         endm
  63.  
  64. MTry_Move_Right    macro
  65.     cmp.w    #G_EMPTY,grid_type+ONE_RIGHT(a2)
  66.     bne.s    .\@
  67.     cmp.b    #EMPTY_REAL_EMPTY,grid_data+ONE_RIGHT(a2)
  68. *    bne.s    .\@
  69.     bne    .next
  70.     move.w    #TRANS_MOVER_RIGHT,grid_trans(a2)
  71.     move.w    #DRAW_MOVER_RIGHT0,grid_draw(a2)
  72.     move.w    #DRAW_NOT,grid_draw+ONE_RIGHT(a2)
  73.     move.b    #4,grid_dirty(a2)
  74.     move.b    #MOVING_RIGHT,grid_data(a2)
  75.     move.b    #EMPTY_OCC_MOVER,grid_data+ONE_RIGHT(a2)
  76.     bra    .next
  77. .\@
  78.         endm
  79.  
  80. MTry_Move_Up    macro
  81.     cmp.w    #G_EMPTY,grid_type+ONE_UP(a2)
  82.     bne.s    .\@
  83.     move.b    grid_data+ONE_UP(a2),d1
  84.     cmp.b    #EMPTY_OCC_ROCK_DOWN,d1
  85.     bne.s    .d\@
  86.     move.w    #TRANS_NONE,grid_trans(a2)
  87.     move.w    #TRANS_KILL_MOVER,grid_trans+ONE_UP+ONE_UP(a2)
  88.     bra    .next
  89. .d\@    cmp.b    #EMPTY_REAL_EMPTY,d1
  90.     bne.s    .\@
  91.     move.w    #TRANS_MOVER_UP,grid_trans(a2)
  92.     move.w    #DRAW_MOVER_UP0,grid_draw(a2)
  93.     move.b    #4,grid_dirty(a2)
  94.     move.b    #MOVING_UP,grid_data(a2)
  95.     move.w    #DRAW_NOT,grid_draw+ONE_UP(a2)
  96.     move.b    #EMPTY_OCC_MOVER,grid_data+ONE_UP(a2)
  97.     bra    .next
  98. .\@
  99.         endm
  100.  
  101. MTry_Move_Down    macro
  102.     cmp.w    #G_EMPTY,grid_type+ONE_DOWN(a2)
  103.     bne.s    .\@
  104.     cmp.b    #EMPTY_REAL_EMPTY,grid_data+ONE_DOWN(a2)
  105.     bne.s    .\@
  106.     move.w    #TRANS_MOVER_DOWN,grid_trans(a2)
  107.     move.w    #DRAW_MOVER_DOWN0,grid_draw(a2)
  108.     move.w    #DRAW_NOT,grid_draw+ONE_DOWN(a2)
  109.     move.b    #4,grid_dirty(a2)
  110.     move.b    #MOVING_DOWN,grid_data(a2)
  111.     move.b    #EMPTY_OCC_MOVER,grid_data+ONE_DOWN(a2)
  112.     bra    .next
  113. .\@
  114.         endm
  115.  
  116. BTry_Move_Left    macro
  117.     cmp.w    #G_EMPTY,grid_type+ONE_LEFT(a2)
  118.     bne.s    .\@
  119.     cmp.b    #EMPTY_REAL_EMPTY,grid_data+ONE_LEFT(a2)
  120. *    bne.s    .\@
  121.     bne    .next
  122.     move.w    #TRANS_BUTTERFLY_LEFT,grid_trans(a2)
  123.     move.w    #DRAW_BUTTERFLY_LEFT0,grid_draw(a2)
  124.     move.w    #DRAW_NOT,grid_draw+ONE_LEFT(a2)
  125.     move.b    #4,grid_dirty(a2)
  126.     move.b    #MOVING_LEFT,grid_data(a2)
  127.     move.b    #EMPTY_OCC_MOVER,grid_data+ONE_LEFT(a2)
  128.     bra    .next
  129. .\@
  130.         endm
  131.  
  132. BTry_Move_Right    macro
  133.     cmp.w    #G_EMPTY,grid_type+ONE_RIGHT(a2)
  134.     bne.s    .\@
  135.     cmp.b    #EMPTY_REAL_EMPTY,grid_data+ONE_RIGHT(a2)
  136. *    bne    .\@
  137.     bne    .next
  138.     move.w    #TRANS_BUTTERFLY_RIGHT,grid_trans(a2)
  139.     move.w    #DRAW_BUTTERFLY_RIGHT0,grid_draw(a2)
  140.     move.w    #DRAW_NOT,grid_draw+ONE_RIGHT(a2)
  141.     move.b    #4,grid_dirty(a2)
  142.     move.b    #MOVING_RIGHT,grid_data(a2)
  143.     move.b    #EMPTY_OCC_MOVER,grid_data+ONE_RIGHT(a2)
  144.     bra    .next
  145. .\@
  146.         endm
  147.  
  148. BTry_Move_Up    macro
  149.     cmp.w    #G_EMPTY,grid_type+ONE_UP(a2)
  150.     bne.s    .\@
  151.     move.b    grid_data+ONE_UP(a2),d1
  152.     cmp.b    #EMPTY_OCC_ROCK_DOWN,d1
  153.     bne.s    .d\@
  154.     move.w    #TRANS_NONE,grid_trans(a2)
  155.     move.w    #TRANS_KILL_BUTTERFLY,grid_trans+ONE_UP+ONE_UP(a2)
  156.     bra    .next
  157. .d\@    cmp.b    #EMPTY_REAL_EMPTY,d1
  158.     bne.s    .\@
  159.     move.w    #TRANS_BUTTERFLY_UP,grid_trans(a2)
  160.     move.w    #DRAW_BUTTERFLY_UP0,grid_draw(a2)
  161.     move.b    #4,grid_dirty(a2)
  162.     move.b    #MOVING_UP,grid_data(a2)
  163.     move.w    #DRAW_NOT,grid_draw+ONE_UP(a2)
  164.     move.b    #EMPTY_OCC_MOVER,grid_data+ONE_UP(a2)
  165.     bra    .next
  166. .\@
  167.         endm
  168.  
  169. BTry_Move_Down    macro
  170.     cmp.w    #G_EMPTY,grid_type+ONE_DOWN(a2)
  171.     bne.s    .\@
  172.     cmp.b    #EMPTY_REAL_EMPTY,grid_data+ONE_DOWN(a2)
  173.     bne.s    .\@
  174.     move.w    #TRANS_BUTTERFLY_DOWN,grid_trans(a2)
  175.     move.w    #DRAW_BUTTERFLY_DOWN0,grid_draw(a2)
  176.     move.w    #DRAW_NOT,grid_draw+ONE_DOWN(a2)
  177.     move.b    #4,grid_dirty(a2)
  178.     move.b    #MOVING_DOWN,grid_data(a2)
  179.     move.b    #EMPTY_OCC_MOVER,grid_data+ONE_DOWN(a2)
  180.     bra    .next
  181. .\@
  182.         endm
  183.  
  184. Do_Not_Move    macro
  185.     move.w    #TRANS_NONE,grid_trans(a2)
  186.     bra    .next
  187.         endm
  188.  
  189.  
  190. *
  191. * Calculate
  192. *
  193. * A0                        D0
  194. * A1                        D1
  195. * A2 - grid field           D2 - grid_x
  196. * A3 - copy of grid field   D3 - grid_y
  197. * A4 -                      D4
  198. * A5 -                      D5
  199. * A6                        D6
  200. *                           D7
  201.  
  202. Calculate ; (Grid Field) ,a2
  203.  
  204. * Copy For Test Green Fungis
  205.     move.l    a2,a3
  206.  
  207.     move.w    #GRIDF_HEIGHT-1-6,d3                ; skip border
  208.     add.l    #3*GRIDF_WIDTH*grid_sizeof+(3*grid_sizeof),a2    ; skip border
  209. .ll0    move.w    #GRIDF_WIDTH-1-6,d2                ; skip border
  210. .ll1    move.w    grid_type(a2),d0
  211.     cmp.w    #G_DIRT,d0
  212.     beq    .next
  213.     cmp.w    #G_EMPTY,d0
  214.     beq    .next
  215.     cmp.w    #G_BORDER,d0
  216.     beq    .next
  217. *----------------
  218. *  ROCK ROCK ROCK
  219. *----------------
  220. * is it a rock ?
  221.     cmp.w    #G_ROCK,d0
  222.     bne    .pos2
  223. * can it fall strait down ?
  224.     move.w    grid_type+ONE_DOWN(a2),d1
  225.     cmp.w    #G_EMPTY,d1
  226.     beq.s    .remp
  227. * can it kill ted below ?
  228.     cmp.w    #G_TED,d1
  229.     bne.s    .rock00
  230.     cmp.b    #ROCK_MOVING,grid_data(a2)
  231.     bne    .next
  232.     move.w    #TRANS_KILL_TED,grid_trans+ONE_DOWN(a2)
  233.     bra    .next
  234. * can it kill a mover below ?
  235. .rock00    cmp.w    #G_MOVER,d1
  236.     bne.s    .rock0
  237.     cmp.b    #ROCK_MOVING,grid_data(a2)
  238.     bne    .next
  239.     move.w    #TRANS_KILL_MOVER,grid_trans(a2)
  240.     move.b    #MOVING_NOT,grid_data+ONE_DOWN(a2)
  241.     bra    .next
  242. * can it kill a butterfly below ?
  243. .rock0    cmp.w    #G_BUTTERFLY,d1
  244.     bne.s    .rock1
  245.     cmp.b    #ROCK_MOVING,grid_data(a2)
  246.     bne    .next
  247.     move.w    #TRANS_KILL_BUTTERFLY,grid_trans(a2)
  248.     move.b    #MOVING_NOT,grid_data+ONE_DOWN(a2)
  249.     bra    .next
  250.  
  251. .remp    cmp.b    #EMPTY_REAL_EMPTY,grid_data+ONE_DOWN(a2)
  252.     bne.s    .rock1
  253.     move.w    #TRANS_ROCK_DOWN,grid_trans(a2)
  254.     move.w    #DRAW_ROCK_DOWN0,grid_draw(a2)
  255.     move.w    #DRAW_NOT,grid_draw+ONE_DOWN(a2)
  256.     move.b    #4,grid_dirty(a2)
  257.     move.b    #EMPTY_OCC_ROCK_DOWN,grid_data+ONE_DOWN(a2)
  258.     move.b    #ROCK_MOVING,grid_data(a2)
  259.     bra    .next
  260.  
  261. * can it fall sideways to the left
  262. .rock1    cmp.w    #G_EMPTY,grid_type+ONE_DOWN+ONE_LEFT(a2)
  263.     bne.s    .rock2
  264.     cmp.b    #EMPTY_REAL_EMPTY,grid_data+ONE_DOWN+ONE_LEFT(a2)
  265.     bne.s    .rock2
  266.  
  267. * Is the rock on top of another rock or diamond ?
  268.     move.w    grid_type+ONE_DOWN(a2),d1
  269.     cmp.w    #G_ROCK,d1
  270.     beq.s    .roc8
  271.     cmp.w    #G_DIAMOND,d1
  272.     bne    .rock_stops
  273.  
  274. * Can it move to the left ?
  275. .roc8    cmp.w    #G_EMPTY,grid_type+ONE_LEFT(a2)
  276.     bne.s    .rock2
  277.     cmp.b    #EMPTY_REAL_EMPTY,grid_data+ONE_LEFT(a2)
  278.     bne.s    .rock2
  279.     move.w    #TRANS_ROCK_LEFT,grid_trans(a2)
  280.     move.w    #DRAW_ROCK_LEFT0,grid_draw(a2)
  281.     move.w    #DRAW_NOT,grid_draw+ONE_LEFT(a2)
  282.     move.b    #4,grid_dirty(a2)
  283.     move.b    #EMPTY_OCC_ROCK,grid_data+ONE_LEFT(a2)
  284.     move.b    #ROCK_MOVING,grid_data(a2)
  285.     bra    .next
  286.  
  287. * can it fall sideways to the right
  288. .rock2    cmp.w    #G_EMPTY,grid_type+ONE_DOWN+ONE_RIGHT(a2)
  289.     bne    .rock_stops
  290.     cmp.b    #EMPTY_REAL_EMPTY,grid_data+ONE_DOWN+ONE_RIGHT(a2)
  291.     bne    .rock_stops
  292.  
  293. * Is the rock on top of another rock or diamond ?
  294.     move.w    grid_type+ONE_DOWN(a2),d1
  295.     cmp.w    #G_ROCK,d1
  296.     beq.s    .roc9
  297.     cmp.w    #G_DIAMOND,d1
  298.     bne    .rock_stops
  299.  
  300. * Can it move to the Right ?
  301. .roc9    cmp.w    #G_EMPTY,grid_type+ONE_RIGHT(a2)
  302.     bne    .rock_stops
  303.     cmp.b    #EMPTY_REAL_EMPTY,grid_data+ONE_RIGHT(a2)
  304.     bne    .rock_stops
  305.     move.w    #TRANS_ROCK_RIGHT,grid_trans(a2)
  306.     move.w    #DRAW_ROCK_RIGHT0,grid_draw(a2)
  307.     move.w    #DRAW_NOT,grid_draw+ONE_RIGHT(a2)
  308.     move.b    #4,grid_dirty(a2)
  309.     move.b    #EMPTY_OCC_ROCK,grid_data+ONE_RIGHT(a2)
  310.     move.b    #ROCK_MOVING,grid_data(a2)
  311.     bra    .next
  312.  
  313. .rock_stops
  314.     move.b    #ROCK_STEADY,grid_data(a2)
  315.     bra    .next
  316. .pos2
  317. *-------------------
  318. *  MOVER MOVER MOVER
  319. *-------------------
  320.     cmp.w    #G_MOVER,d0
  321.     bne    .pos3
  322.     move.b    grid_data(a2),d1
  323. * is the mover to be killed ?
  324.     cmp.b    #MOVING_NOT,d1
  325.     beq    .next
  326. * calculate moving direction
  327.     cmp.b    #MOVING_UP,d1
  328.     bne    .move2
  329.     MTry_Move_Left
  330.     MTry_Move_Up
  331.     MTry_Move_Right
  332.     MTry_Move_Down
  333.     Do_Not_Move
  334. .move2    cmp.b    #MOVING_DOWN,d1
  335.     bne    .move3
  336.     MTry_Move_Right
  337.     MTry_Move_Down
  338.     MTry_Move_Left
  339.     MTry_Move_Up
  340.     Do_Not_Move
  341. .move3    cmp.b    #MOVING_LEFT,d1
  342.     bne    .move4
  343.     MTry_Move_Down
  344.     MTry_Move_Left
  345.     MTry_Move_Up
  346.     MTry_Move_Right
  347.     Do_Not_Move
  348. .move4    MTry_Move_Up
  349.     MTry_Move_Right
  350.     MTry_Move_Down
  351.     MTry_Move_Left
  352.     Do_Not_Move
  353.  
  354. .pos3
  355. *---------------------
  356. *  BUTTERFLY BUTTERFLY
  357. *---------------------
  358.     cmp.w    #G_BUTTERFLY,d0
  359.     bne    .pos4
  360.     move.b    grid_data(a2),d1
  361. * is the butterfly to be killed ?
  362.     cmp.b    #MOVING_NOT,d1
  363.     beq    .next
  364.  
  365.     cmp.w    #G_FUNGIS,grid_type+ONE_LEFT(a2)
  366.     bne.s    .bf1
  367.     move.w    #TRANS_NONE,grid_trans(a2)
  368.     move.w    #TRANS_KILL_BUTTERFLY4,grid_trans+ONE_LEFT(a2)
  369.     bra    .next
  370. .bf1    cmp.w    #G_FUNGIS,grid_type+ONE_RIGHT(a2)
  371.     bne.s    .bf2
  372.     move.w    #TRANS_NONE,grid_trans(a2)
  373.     move.w    #TRANS_KILL_BUTTERFLY2,grid_trans+ONE_RIGHT(a2)
  374.     bra    .next
  375. .bf2    cmp.w    #G_FUNGIS,grid_type+ONE_UP(a2)
  376.     bne.s    .bf3
  377.     move.w    #TRANS_NONE,grid_trans(a2)
  378.     move.w    #TRANS_KILL_BUTTERFLY,grid_trans+ONE_UP(a2)
  379.     bra    .next
  380. .bf3    cmp.w    #G_FUNGIS,grid_type+ONE_DOWN(a2)
  381.     bne.s    .butt0
  382.     move.w    #TRANS_NONE,grid_trans(a2)
  383.     move.w    #TRANS_KILL_BUTTERFLY3,grid_trans+ONE_DOWN(a2)
  384.     bra    .next
  385.  
  386. .butt0    move.b    grid_data(a2),d1
  387.     cmp.b    #MOVING_UP,d1
  388.     bne    .butt2
  389.     BTry_Move_Right
  390.     BTry_Move_Up
  391.     BTry_Move_Left
  392.     BTry_Move_Down
  393.     Do_Not_Move
  394. .butt2    cmp.b    #MOVING_DOWN,d1
  395.     bne    .butt3
  396.     BTry_Move_Left
  397.     BTry_Move_Down
  398.     BTry_Move_Right
  399.     BTry_Move_Up
  400.     Do_Not_Move
  401. .butt3    cmp.b    #MOVING_LEFT,d1
  402.     bne    .butt4
  403.     BTry_Move_Up
  404.     BTry_Move_Left
  405.     BTry_Move_Down
  406.     BTry_Move_Right
  407.     Do_Not_Move
  408. .butt4    BTry_Move_Down
  409.     BTry_Move_Right
  410.     BTry_Move_Up
  411.     BTry_Move_Left
  412.     Do_Not_Move
  413.  
  414. .pos4
  415. *---------------------
  416. *  DIAMOND DIAMOND
  417. *---------------------
  418.     cmp.w    #G_DIAMOND,d0
  419.     bne    .pos5
  420. * can it fall strait down ?
  421.     cmp.w    #G_EMPTY,grid_type+ONE_DOWN(a2)
  422.     bne.s    .diamond1
  423.     cmp.b    #EMPTY_REAL_EMPTY,grid_data+ONE_DOWN(a2)
  424.     bne.s    .diamond1
  425.     move.w    #TRANS_DIAMOND_DOWN,grid_trans(a2)
  426.     move.w    #DRAW_DIAMOND_DOWN0,grid_draw(a2)
  427.     move.w    #DRAW_NOT,grid_draw+ONE_DOWN(a2)
  428.     move.b    #4,grid_dirty(a2)
  429.     move.b    #EMPTY_OCC_DIAMOND,grid_data+ONE_DOWN(a2)
  430.     bra    .next
  431. * can it fall sideways to the left
  432. .diamond1
  433.     cmp.w    #G_EMPTY,grid_type+ONE_DOWN+ONE_LEFT(a2)
  434.     bne.s    .diamond2
  435.     cmp.b    #EMPTY_REAL_EMPTY,grid_data+ONE_DOWN+ONE_LEFT(a2)
  436.     bne.s    .diamond2
  437.  
  438. * Is the diamond on top of another rock or diamond ?
  439.     move.w    grid_type+ONE_DOWN(a2),d1
  440.     cmp.w    #G_ROCK,d1
  441.     beq.s    .dia8
  442.     cmp.w    #G_DIAMOND,d1
  443.     bne.s    .diamond2
  444.  
  445. * Can it move to the Left ?
  446. .dia8    cmp.w    #G_EMPTY,grid_type+ONE_LEFT(a2)
  447.     bne.s    .diamond2
  448.     cmp.b    #EMPTY_REAL_EMPTY,grid_data+ONE_LEFT(a2)
  449.     bne.s    .diamond2
  450.     move.w    #TRANS_DIAMOND_LEFT,grid_trans(a2)
  451.     move.w    #DRAW_DIAMOND_LEFT0,grid_draw(a2)
  452.     move.w    #DRAW_NOT,grid_draw+ONE_LEFT(a2)
  453.     move.b    #4,grid_dirty(a2)
  454.     move.b    #EMPTY_OCC_DIAMOND,grid_data+ONE_LEFT(a2)
  455.     bra    .next
  456. * can it fall sideways to the right
  457. .diamond2
  458.     cmp.w    #G_EMPTY,grid_type+ONE_DOWN+ONE_RIGHT(a2)
  459.     bne    .next
  460.     cmp.b    #EMPTY_REAL_EMPTY,grid_data+ONE_DOWN+ONE_RIGHT(a2)
  461.     bne    .next
  462.  
  463. * Is the diamond on top of another rock or diamond ?
  464.     move.w    grid_type+ONE_DOWN(a2),d1
  465.     cmp.w    #G_ROCK,d1
  466.     beq.s    .dia9
  467.     cmp.w    #G_DIAMOND,d1
  468.     bne    .next
  469.  
  470. * Can it move to the Right ?
  471. .dia9    cmp.w    #G_EMPTY,grid_type+ONE_RIGHT(a2)
  472.     bne    .next
  473.     cmp.b    #EMPTY_REAL_EMPTY,grid_data+ONE_RIGHT(a2)
  474.     bne    .next
  475.     move.w    #TRANS_DIAMOND_RIGHT,grid_trans(a2)
  476.     move.w    #DRAW_DIAMOND_RIGHT0,grid_draw(a2)
  477.     move.w    #DRAW_NOT,grid_draw+ONE_RIGHT(a2)
  478.     move.b    #4,grid_dirty(a2)
  479.     move.b    #EMPTY_OCC_DIAMOND,grid_data+ONE_RIGHT(a2)
  480.     bra    .next
  481. .diamond3
  482.  
  483. *---------------------
  484. *  TED TED TED TED
  485. *---------------------
  486.  
  487. .pos5    cmp.w    #G_TED,d0
  488.     bne    .pos6
  489.  
  490. * did ted reach the exit and wins ?
  491.     move.w    ted_reach_limit,d0
  492.     beq.s    .ktd
  493.     cmp.w    #G_EXIT,grid_type+ONE_LEFT(a2)
  494.     beq.s    .tedwins
  495.     cmp.w    #G_EXIT,grid_type+ONE_RIGHT(a2)
  496.     beq.s    .tedwins
  497.     cmp.w    #G_EXIT,grid_type+ONE_UP(a2)
  498.     beq.s    .tedwins
  499.     cmp.w    #G_EXIT,grid_type+ONE_DOWN(a2)
  500.     bne.s    .ktd
  501. .tedwins
  502.     move.w    #TRUE,ted_wins_flag
  503.  
  504. * Is Ted To be Killed ?
  505. .ktd    cmp.w    #TRANS_KILL_TED,grid_trans(a2)
  506.     beq    .next
  507.     cmp.w    #TIMESUP,time_flag
  508.     beq.s    .killTed
  509.     cmp.w    #G_MOVER,grid_type+ONE_DOWN(a2)
  510.     beq.s    .killTed
  511.     cmp.w    #G_MOVER,grid_type+ONE_UP(a2)
  512.     beq.s    .killTed
  513.     cmp.w    #G_MOVER,grid_type+ONE_LEFT(a2)
  514.     beq.s    .killTed
  515.     cmp.w    #G_MOVER,grid_type+ONE_RIGHT(a2)
  516.     beq.s    .killTed
  517.     cmp.w    #G_BUTTERFLY,grid_type+ONE_DOWN(a2)
  518.     beq.s    .killTed
  519.     cmp.w    #G_BUTTERFLY,grid_type+ONE_UP(a2)
  520.     beq.s    .killTed
  521.     cmp.w    #G_BUTTERFLY,grid_type+ONE_LEFT(a2)
  522.     beq.s    .killTed
  523.     cmp.w    #G_BUTTERFLY,grid_type+ONE_RIGHT(a2)
  524.     bne.s    .joyst
  525. .killTed
  526.     move.w    #TRANS_KILL_TED,grid_trans(a2)
  527.     move.w    #FALSE,ted_wins_flag
  528.     bra    .next
  529.  
  530. * Read Joystick
  531. .joyst    move.w    $dff00c,d0        ; Joystick 1
  532.  
  533.     btst    #0,d0
  534.     beq.s    .xor1
  535.     btst    #1,d0
  536.     beq    .teddown        bit 0=1 & bit 1=0
  537. .xor0    btst    #8,d0
  538.     beq.s    .xor2
  539.     btst    #9,d0
  540.     beq    .tedup            bit 8=1 & bit 9=0 
  541.     bra.s    .tedlr
  542. .xor1    btst    #1,d0
  543.     bne    .teddown        bit 0=0 & bit 1=1
  544.     bra.s    .xor0
  545. .xor2    btst    #9,d0            bit 8=0 & bit 9=1
  546.     bne    .tedup
  547. .tedlr    btst    #1,d0
  548.     bne    .tedright
  549.     btst    #9,d0
  550.     bne    .tedleft
  551. * ted does not want to move
  552.     bra    .next
  553.  
  554. *------------------
  555. * Ted Left Ted Left
  556. *------------------
  557.  
  558. .tedleft
  559.     move.b    $bfe001,d0
  560.     btst    #7,d0
  561.     beq    .fireleft
  562.  
  563. * Try to move to the left
  564. * Is there a diamond to the left of Ted
  565.     move.w    grid_type+ONE_LEFT(a2),d1
  566.     cmp.w    #G_DIAMOND,d1
  567.     bne.s    .tleft0
  568. * Is it falling down ?
  569.     move.w    grid_trans+ONE_LEFT(a2),d1
  570.     cmp.w    #TRANS_NONE,d1
  571.     bne    .next
  572. * Ted Collects Diamond and moves to the Left
  573.     jsr    Update_Score
  574.     bra.s    .tleft1
  575. * Is there a empty grid to the left of Ted
  576. .tleft0    cmp.w    #G_EMPTY,d1
  577.     bne.s    .tleft2
  578.     cmp.b    #EMPTY_REAL_EMPTY,grid_data+ONE_LEFT(a2)
  579.     bne    .next
  580. * Move Ted one grid to the left
  581. .tleft1    move.w    #TRANS_TED_LEFT,grid_trans(a2)
  582.     move.w    #DRAW_TED_LEFT0,grid_draw(a2)
  583.     move.w    #DRAW_NOT,grid_draw+ONE_LEFT(a2)
  584.     move.b    #4,grid_dirty(a2)
  585.     move.b    #EMPTY_OCC_TED,grid_data+ONE_LEFT(a2)
  586.     bra    .tedlupdate
  587. * Is the a dirt grid to the right of Ted
  588. .tleft2    cmp.w    #G_DIRT,d1
  589.     bne    .next
  590. * Ted moves to the dirt to the left
  591.     move.w    #TRANS_TED_LEFT,grid_trans(a2)
  592.     move.w    #DRAW_TED_DIRT_LEFT0,grid_draw(a2)
  593.     move.w    #DRAW_NOT,grid_draw+ONE_LEFT(a2)
  594.     move.b    #4,grid_dirty(a2)
  595.     bra    .tedlupdate
  596.  
  597. .fireleft
  598.     move.w    grid_type+ONE_LEFT(a2),d1
  599.     cmp.w    #G_DIRT,d1
  600.     bne    .fil2
  601. * Ted empties the grid to the left of him.
  602.     move.w    #DRAW_EMPTY,grid_draw+ONE_LEFT(a2)
  603.     move.w    #TRANS_TO_EMPTY,grid_trans+ONE_LEFT(a2)
  604.     move.b    #2,grid_dirty+ONE_LEFT(a2)
  605.     bra    .next
  606. .fil2    cmp.w    #G_ROCK,d1
  607.     bne    .next
  608. * is the rock about to fall any direction ?
  609.     move.w    grid_trans+ONE_LEFT(a2),d1
  610.     cmp.w    #TRANS_NONE,d1
  611.     bne    .next
  612. * can we move the rock ?
  613.     move.w    grid_type+ONE_LEFT+ONE_LEFT(a2),d1
  614.     cmp.w    #G_EMPTY,d1
  615.     bne    .next
  616.     cmp.b    #EMPTY_REAL_EMPTY,grid_data+ONE_LEFT+ONE_LEFT(a2)
  617.     bne    .next
  618. * Ted moves the rock to the left of him.
  619.     move.w    #DRAW_NOT,grid_draw+ONE_LEFT(a2)
  620.     move.b    #EMPTY_OCC_ROCK,grid_data+ONE_LEFT+ONE_LEFT(a2)
  621.     move.w    #TRANS_TED_MOVES_ROCK_LEFT,grid_trans(a2)
  622.     move.w    #DRAW_TED_ROCK_LEFT0,grid_draw(a2)
  623.     move.b    #4,grid_dirty(a2)
  624.  
  625. * Update Ted co-ordinates
  626. .tedlupdate
  627.     move.l    ted_bitmap_x,d0
  628.     subq.l    #grid_sizeof,d0
  629.     move.l    animate_offset_x,d1
  630.     beq.s    .noscrl
  631.     bls.s    .noscrl
  632.     cmp.l    #SCROLL_RIGHT,d0
  633.     bhs.s    .noscrl
  634.     move.w    grid_trans(a2),d1
  635.     cmp.w    #TRANS_TED_MOVES_ROCK_LEFT,d1
  636.     bne.s    .lnorm
  637.     move.w    #TRANS_TED_SCROLL_MOVES_ROCK_LEFT,grid_trans(a2)
  638.     bra.s    .lnorm2
  639. .lnorm    move.w    #TRANS_LEFT_SCROLL_RIGHT,grid_trans(a2)
  640. .lnorm2    move.w    #DO_SCROLL,flag_view_scroll_right
  641. .noscrl    move.l    d0,ted_bitmap_x
  642.     move.l    ted_grid_field_x,d0
  643.     subq.l    #grid_sizeof,d0
  644.     move.l    d0,ted_grid_field_x
  645.     bra    .next
  646.  
  647.  
  648. *--------------------
  649. * Ted Right Ted Right
  650. *--------------------
  651.  
  652. .tedright
  653.     move.b    $bfe001,d0
  654.     btst    #7,d0
  655.     beq    .fireright
  656. * Try to move to the right
  657.     move.w    grid_type+ONE_RIGHT(a2),d1
  658.     cmp.w    #G_DIAMOND,d1
  659.     bne.s    .tright0
  660. * There is a diamond
  661. * Is it falling down ?
  662.     move.w    grid_type+ONE_DOWN+ONE_RIGHT(a2),d1
  663.     cmp.w    #G_EMPTY,d1
  664.     bne.s    .trr0
  665.     cmp.b    #EMPTY_REAL_EMPTY,grid_data+ONE_DOWN+ONE_RIGHT(a2)
  666.     beq    .next
  667. * Can is fall sideways to the right ?
  668. .trr0    move.w    grid_type+ONE_RIGHT+ONE_RIGHT(a2),d1
  669.     cmp.w    #G_EMPTY,d1
  670.     bne.s    .trghd1
  671.     move.w    grid_type+ONE_RIGHT+ONE_DOWN(a2),d1
  672.     cmp.w    #G_ROCK,d1
  673.     beq    .trr1
  674.     cmp.w    #G_DIAMOND,d1
  675.     bne.s    .trghd1
  676. .trr1    move.w    grid_type+ONE_RIGHT+ONE_RIGHT+ONE_DOWN(a2),d1
  677.     cmp.w    #G_EMPTY,d1
  678.     beq    .next
  679.     bra    .trghd1
  680.  
  681. * Is there a empty grid to the right of Ted
  682. .tright0
  683.     cmp.w    #G_EMPTY,d1
  684.     bne    .tright2
  685.     cmp.b    #EMPTY_REAL_EMPTY,grid_data+ONE_RIGHT(a2)
  686.     bne    .next
  687.     bra    .tright1
  688. * Ted Collect Diamond and moves to the right
  689. .trghd1    jsr    Update_Score
  690. * Ted moves to the right
  691. .tright1
  692.     move.w    #TRANS_TED_RIGHT,grid_trans(a2)
  693.     move.w    #DRAW_TED_RIGHT0,grid_draw(a2)
  694.     move.w    #DRAW_NOT,grid_draw+ONE_RIGHT(a2)
  695.     move.b    #4,grid_dirty(a2)
  696.     move.b    #EMPTY_OCC_TED,grid_data+ONE_RIGHT(a2)
  697.     bra    .tedrupdate
  698. * Is the a dirt grid to the right of Ted
  699. .tright2
  700.     cmp.w    #G_DIRT,d1
  701.     bne    .next
  702. * Ted moves to the dirt to the right
  703.     move.w    #TRANS_TED_RIGHT,grid_trans(a2)
  704.     move.w    #DRAW_TED_DIRT_RIGHT0,grid_draw(a2)
  705.     move.w    #DRAW_NOT,grid_draw+ONE_RIGHT(a2)
  706.     move.b    #4,grid_dirty(a2)
  707.     bra    .tedrupdate
  708. .fireright
  709.     move.w    grid_type+ONE_RIGHT(a2),d1
  710.     cmp.w    #G_DIRT,d1
  711.     bne    .firr1
  712. * Ted empties the grid to the right of him.
  713.     move.w    #DRAW_EMPTY,grid_draw+ONE_RIGHT(a2)
  714.     move.w    #TRANS_TO_EMPTY,grid_trans+ONE_RIGHT(a2)
  715.     move.b    #2,grid_dirty+ONE_RIGHT(a2)
  716.     bra    .next
  717. .firr1    cmp.w    #G_ROCK,d1
  718.     bne    .next
  719. * is the rock about to fall any direction ?
  720.     move.w    grid_type+ONE_DOWN+ONE_RIGHT(a2),d1
  721.     cmp.w    #G_EMPTY,d1
  722.     bne.s    .firr2
  723.     cmp.b    #EMPTY_REAL_EMPTY,grid_data+ONE_DOWN+ONE_RIGHT(a2)
  724.     beq    .next
  725. .firr2    cmp.w    #G_MOVER,d1
  726.     beq    .next
  727. * Can the rock fall side ways to the right
  728. .firr3    move.w    grid_type+ONE_RIGHT+ONE_RIGHT(a2),d1
  729.     cmp.w    #G_EMPTY,d1
  730.     bne    .next
  731.     move.w    grid_type+ONE_RIGHT+ONE_DOWN(a2),d1
  732.     cmp.w    #G_ROCK,d1
  733.     beq    .firr0
  734.     cmp.w    #G_DIAMOND,d1
  735.     bne.s    .firr4
  736. .firr0    move.w    grid_type+ONE_RIGHT+ONE_RIGHT+ONE_DOWN(a2),d1
  737.     cmp.w    #G_EMPTY,d1
  738.     beq    .next
  739. * Ted moves the rock to the right of him.
  740. .firr4    move.w    #DRAW_NOT,grid_draw+ONE_RIGHT(a2)
  741.     move.b    #EMPTY_OCC_ROCK,grid_data+ONE_RIGHT+ONE_RIGHT(a2)
  742.     move.w    #TRANS_TED_MOVES_ROCK_RIGHT,grid_trans(a2)
  743.     move.w    #DRAW_TED_ROCK_RIGHT0,grid_draw(a2)
  744.     move.b    #4,grid_dirty(a2)
  745.  
  746. * Update Ted co-ordinates
  747. .tedrupdate
  748.     move.l    ted_bitmap_x,d0
  749.     addq.l    #grid_sizeof,d0
  750.     move.l    animate_offset_x,d1
  751.     cmp.l    #SCROLL_LEFT_MAX,d1
  752.     bhs.s    .noscrr
  753.     cmp.l    #SCROLL_LEFT,d0
  754.     bls.s    .noscrr
  755.     move.w    grid_trans(a2),d1
  756.     cmp.w    #TRANS_TED_MOVES_ROCK_RIGHT,d1
  757.     bne.s    .rnorm
  758.     move.w    #TRANS_TED_SCROLL_MOVES_ROCK_RIGHT,grid_trans(a2)
  759.     bra.s    .rnorm2
  760. .rnorm    move.w    #TRANS_RIGHT_SCROLL_LEFT,grid_trans(a2)
  761. .rnorm2    move.w    #DO_SCROLL,flag_view_scroll_left
  762. .noscrr    move.l    d0,ted_bitmap_x
  763.  
  764.     move.l    ted_grid_field_x,d0
  765.     add.l    #grid_sizeof,d0
  766.     move.l    d0,ted_grid_field_x
  767.  
  768.     bra    .next
  769.  
  770. *--------------
  771. * Ted Up Ted Up
  772. *--------------
  773.  
  774. .tedup
  775.     move.b    $bfe001,d0
  776.     btst    #7,d0
  777.     beq    .fireup
  778. * Try to move up
  779.  
  780. * Is there a diamond above ted ?
  781.     move.w    grid_type+ONE_UP(a2),d1
  782.     cmp.w    #G_DIAMOND,d1
  783.     bne.s    .tuu1
  784. * It is falling down ?
  785.     move.w    grid_trans+ONE_UP(a2),d1
  786.     cmp.w    #TRANS_NONE,d1
  787.     bne    .next
  788. * Ted Collects Diamond and moves to the Up
  789.     jsr    Update_Score
  790.     bra.s    .touk0
  791. * Is there a empty grid above ted ?
  792. .tuu1    cmp.w    #G_EMPTY,d1
  793.     bne.s    .touk1
  794.     cmp.b    #EMPTY_REAL_EMPTY,grid_data+ONE_UP(a2)
  795.     bne    .next
  796. * Ted moves to the up
  797. .touk0    move.w    #TRANS_TED_UP,grid_trans(a2)
  798.     move.w    #DRAW_TED_UP0,grid_draw(a2)
  799.     move.b    #4,grid_dirty(a2)
  800.     move.b    #EMPTY_OCC_TED,grid_data+ONE_UP(a2)
  801.     bra    .teduupdate
  802. .touk1    cmp.w    #G_DIRT,d1
  803.     bne    .next
  804. * Ted moves to the up trough the dirt
  805.     move.w    #TRANS_TED_UP,grid_trans(a2)
  806.     move.w    #DRAW_TED_DIRT_UP0,grid_draw(a2)
  807.     move.b    #4,grid_dirty(a2)
  808.     bra    .teduupdate
  809. .fireup
  810.     move.w    grid_type+ONE_UP(a2),d1
  811.     cmp.w    #G_DIRT,d1
  812.     bne    .next
  813. * Ted empties the grid above him.
  814.     move.w    #DRAW_EMPTY,grid_draw+ONE_UP(a2)
  815.     move.w    #TRANS_TO_EMPTY,grid_trans+ONE_UP(a2)
  816.     move.b    #2,grid_dirty+ONE_UP(a2)
  817.     bra    .next
  818.  
  819. * Update Ted co-ordinates
  820. .teduupdate
  821.     move.l    ted_bitmap_y,d0
  822.     sub.l    #grid_sizeof*GRIDF_WIDTH,d0
  823.     move.l    animate_offset_y,d1
  824.     beq.s    .noscru
  825.     bls.s    .noscru
  826.     cmp.l    #SCROLL_DOWN,d0
  827.     bhs.s    .noscru
  828.     move.w    #TRANS_UP_SCROLL_DOWN,grid_trans(a2)
  829.     move.w    #DO_SCROLL,flag_view_scroll_down
  830. .noscru    move.l    d0,ted_bitmap_y
  831.     move.l    ted_grid_field_y,d0
  832.     sub.l    #grid_sizeof*GRIDF_WIDTH,d0
  833.     move.l    d0,ted_grid_field_y
  834.     bra    .next
  835.  
  836. *------------------
  837. * Ted Down Ted Down
  838. *------------------
  839.  
  840. .teddown
  841.     move.b    $bfe001,d0
  842.     btst    #7,d0
  843.     beq    .firedown
  844. * Try to move down
  845. * Is there a diamond below ted
  846.     move.w    grid_type+ONE_DOWN(a2),d1
  847.     cmp.w    #G_DIAMOND,d1
  848.     bne.s    .tdd1
  849. * Is it falling down ?
  850.     move.w    grid_type+ONE_DOWN+ONE_DOWN(a2),d1
  851.     cmp.w    #G_EMPTY,d1
  852.     bne.s    .tdd2
  853.     cmp.b    #EMPTY_REAL_EMPTY,grid_data+ONE_DOWN+ONE_DOWN(a2)
  854.     beq    .next
  855. * Can is fall sideways to the right ?
  856. .tdd2    move.w    grid_type+ONE_DOWN+ONE_RIGHT(a2),d1
  857.     cmp.w    #G_EMPTY,d1
  858.     bne.s    .toddk1
  859.     move.w    grid_type+ONE_DOWN+ONE_DOWN(a2),d1
  860.     cmp.w    #G_ROCK,d1
  861.     beq    .tdd3
  862.     cmp.w    #G_DIAMOND,d1
  863.     bne.s    .toddk1
  864. .tdd3    move.w    grid_type+ONE_DOWN+ONE_RIGHT+ONE_DOWN(a2),d1
  865.     cmp.w    #G_EMPTY,d1
  866.     beq    .next
  867.     bra    .toddk1
  868.  
  869. * Is there a empty grid below ted
  870. .tdd1    cmp.w    #G_EMPTY,d1
  871.     bne.s    .todk2
  872.     cmp.b    #EMPTY_REAL_EMPTY,grid_data+ONE_DOWN(a2)
  873.     bne    .next
  874.     bra    .todk1
  875.  
  876. * Ted Collects Diamond and moves down
  877. .toddk1    jsr    Update_Score
  878.  
  879. * Ted moves to the down
  880. .todk1    move.w    #TRANS_TED_DOWN,grid_trans(a2)
  881.     move.w    #DRAW_TED_DOWN0,grid_draw(a2)
  882.     move.w    #DRAW_NOT,grid_draw+ONE_DOWN(a2)
  883.     move.b    #4,grid_dirty(a2)
  884.     move.b    #EMPTY_OCC_TED,grid_data+ONE_DOWN(a2)
  885.     bra    .teddupdate
  886. .todk2    cmp.w    #G_DIRT,d1
  887.     bne    .next
  888. * Ted moves to the down trough the dirt
  889.     move.w    #TRANS_TED_DOWN,grid_trans(a2)
  890.     move.w    #DRAW_TED_DIRT_DOWN0,grid_draw(a2)
  891.     move.w    #DRAW_NOT,grid_draw+ONE_DOWN(a2)
  892.     move.b    #4,grid_dirty(a2)
  893.     bra    .teddupdate
  894.  
  895. .firedown
  896.     move.w    grid_type+ONE_DOWN(a2),d1
  897.     cmp.w    #G_DIRT,d1
  898.     bne    .next
  899. * Ted empties the grid above him.
  900.     move.w    #DRAW_EMPTY,grid_draw+ONE_DOWN(a2)
  901.     move.w    #TRANS_TO_EMPTY,grid_trans+ONE_DOWN(a2)
  902.     move.b    #2,grid_dirty+ONE_DOWN(a2)
  903.     bra    .next
  904.  
  905. * Update Ted co-ordinates
  906. .teddupdate
  907.     move.l    ted_bitmap_y,d0
  908.     add.l    #grid_sizeof*GRIDF_WIDTH,d0
  909.     move.l    animate_offset_y,d1
  910.     cmp.l    #SCROLL_UP_MAX,d1
  911.     bhs.s    .noscrd
  912.     cmp.l    #SCROLL_UP,d0
  913.     bls.s    .noscrd
  914.     move.w    #TRANS_DOWN_SCROLL_UP,grid_trans(a2)
  915.     move.w    #DO_SCROLL,flag_view_scroll_up
  916. .noscrd    move.l    d0,ted_bitmap_y
  917.     move.l    ted_grid_field_y,d0
  918.     add.l    #grid_sizeof*GRIDF_WIDTH,d0
  919.     move.l    d0,ted_grid_field_y
  920.     bra    .next
  921.  
  922. *---------------------
  923. *  FUNGIS FUNGIS
  924. *---------------------
  925.  
  926. .pos6    cmp.w    #G_FUNGIS,d0
  927.     bne    .pos7
  928.     bsr    Random
  929.     and.w    #$03f0,d0
  930.     bne    .next
  931. * Try to grow
  932. * Select direction
  933.     bsr    Random
  934.     lsr.w    #8,d0
  935.     and.w    #$0003,d0
  936.     cmp.w    #3,d0
  937.     bne.s    .fung1
  938. * Try to expand to the left
  939.     move.w    grid_type+ONE_LEFT(a2),d0
  940.     cmp.w    #G_DIRT,d0
  941.     beq    .funputl
  942.     cmp.w    #G_EMPTY,d0
  943.     bne    .next
  944.     cmp.b    #EMPTY_REAL_EMPTY,grid_data+ONE_LEFT(a2)
  945.     bne    .next
  946. .funputl
  947. * Expand to the Left
  948.     move.b    #EMPTY_OCC_FUNGIS,grid_data+ONE_LEFT(a2)
  949.     move.w    #TRANS_TO_FUNGIS,grid_trans+ONE_LEFT(a2)
  950.     move.w    #DRAW_FUNGIS_LEFT0,grid_draw+ONE_LEFT(a2)
  951.     move.b    #4,grid_dirty+ONE_LEFT(a2)
  952. * Reset Fungis Timer
  953.     move.w    #0,fungis_timer
  954.     bra    .next
  955. .fung1    cmp.w    #1,d0
  956.     bne.s    .fung2
  957. * Try to expand to the right
  958.     move.w    grid_type+ONE_RIGHT(a2),d0
  959.     cmp.w    #G_DIRT,d0
  960.     beq    .funputr
  961.     cmp.w    #G_EMPTY,d0
  962.     bne    .next
  963.     cmp.b    #EMPTY_REAL_EMPTY,grid_data+ONE_RIGHT(a2)
  964.     bne    .next
  965. .funputr
  966. * Expand to the Right
  967.     move.b    #EMPTY_OCC_FUNGIS,grid_data+ONE_RIGHT(a2)
  968.     move.w    #TRANS_TO_FUNGIS,grid_trans+ONE_RIGHT(a2)
  969.     move.w    #DRAW_FUNGIS_RIGHT0,grid_draw+ONE_RIGHT(a2)
  970.     move.b    #4,grid_dirty+ONE_RIGHT(a2)
  971. * Reset Fungis Timer
  972.     move.w    #0,fungis_timer
  973.     bra    .next
  974. .fung2    cmp.w    #2,d0
  975.     bne.s    .fung3
  976. * Try to expand downwards
  977.     move.w    grid_type+ONE_DOWN(a2),d0
  978.     cmp.w    #G_DIRT,d0
  979.     beq    .funputd
  980.     cmp.w    #G_EMPTY,d0
  981.     bne    .next
  982.     cmp.b    #EMPTY_REAL_EMPTY,grid_data+ONE_DOWN(a2)
  983.     bne    .next
  984. .funputd
  985. * Expand Downwards
  986.     move.b    #EMPTY_OCC_FUNGIS,grid_data+ONE_DOWN(a2)
  987.     move.w    #TRANS_TO_FUNGIS,grid_trans+ONE_DOWN(a2)
  988.     move.w    #DRAW_FUNGIS_DOWN0,grid_draw+ONE_DOWN(a2)
  989.     move.b    #4,grid_dirty+ONE_DOWN(a2)
  990.     move.w    #0,fungis_timer
  991.     bra    .next
  992. .fung3
  993. * Try to expand upwards
  994.     move.w    grid_type+ONE_UP(a2),d0
  995.     cmp.w    #G_DIRT,d0
  996.     beq    .funputu
  997.     cmp.w    #G_EMPTY,d0
  998.     bne    .next
  999.     cmp.b    #EMPTY_REAL_EMPTY,grid_data+ONE_DOWN(a2)
  1000.     bne    .next
  1001. .funputu
  1002. * Expand Upwards
  1003.     move.b    #EMPTY_OCC_FUNGIS,grid_data+ONE_UP(a2)
  1004.     move.w    #TRANS_TO_FUNGIS,grid_trans+ONE_UP(a2)
  1005.     move.w    #DRAW_FUNGIS_UP0,grid_draw+ONE_UP(a2)
  1006.     move.b    #4,grid_dirty+ONE_UP(a2)
  1007.     move.w    #0,fungis_timer
  1008.     bra    .next
  1009.  
  1010. .pos7
  1011.     move.b    d0,d0            dummy
  1012. .next    addq.l    #grid_sizeof,a2
  1013.     dbra    d2,.ll1
  1014.     add.l    #6*grid_sizeof,a2    skip border
  1015.     dbra    d3,.ll0
  1016.  
  1017. ******
  1018. *****  Test If Green Fungus Has Stoped Growing
  1019. ******
  1020.  
  1021.     tst.w    test_fungis
  1022.     beq    .exit
  1023.     move.w    fungis_timer,d0
  1024.     addq.w    #1,d0
  1025.     cmp.w    #MAX_FUN_TIME,d0
  1026.     bne.s    .fungrow
  1027. * Trans Form All Fungis To Diamonds
  1028.     move.l    a3,a2
  1029.     move.w    #GRIDF_HEIGHT-1-6,d3                ; skip border
  1030.     add.l    #3*GRIDF_WIDTH*grid_sizeof+(3*grid_sizeof),a2    ; skip border
  1031. .kk0    move.w    #GRIDF_WIDTH-1-6,d2                ; skip border
  1032. .kk1    cmp.w    #G_FUNGIS,grid_type(a2)
  1033.     bne.s    .kk3
  1034.     move.w    #G_DIAMOND,grid_type(a2)
  1035.     move.w    #TRANS_NONE,grid_trans(a2)
  1036.     move.w    #DRAW_DIAMOND,grid_draw(a2)
  1037.     move.b    #2,grid_dirty(a2)
  1038.     move.b    #0,grid_data(a2)
  1039. .kk3    addq.l    #grid_sizeof,a2
  1040.     dbra    d2,.kk1
  1041.     add.l    #6*grid_sizeof,a2    skip border
  1042.     dbra    d3,.kk0
  1043.     move.w    #FALSE,test_fungis
  1044.     bra    .exit
  1045. .fungrow
  1046.     move.w    d0,fungis_timer
  1047. .exit    rts
  1048.  
  1049.  
  1050.  
  1051. *==============
  1052. * Random    () -> (number),d0
  1053. *==============
  1054.  
  1055. Ran_Regs    REG    d2/d3
  1056.  
  1057. Random    movem.l    Ran_Regs,-(sp)
  1058.     lea    table,a0
  1059.     move.w    j,d2
  1060.     move.w    k,d3
  1061.     move.l    (a0,d2.w),d0    Y[j]
  1062.     add.l    d0,(a0,d3.w)    Y[k]=Y[k]+Y[j]
  1063.  
  1064.     subq.w    #4,d2        j=j-1
  1065.     bne.s    .ll1
  1066.     move.w    #4*55,d2
  1067. .ll1
  1068.     subq.w    #4,d3
  1069.     bne.s    .ll2
  1070.     move.w    #4*55,d3
  1071. .ll2
  1072.     move.w    d2,j
  1073.     move.w    d3,k
  1074.  
  1075.     movem.l    (sp)+,Ran_Regs
  1076.     rts
  1077.  
  1078. j    dc.w    4*24
  1079. k    dc.w    4*55
  1080.  
  1081. table:
  1082.  dc.l    10003
  1083.  dc.l    9923213
  1084.  dc.l    234256
  1085.  dc.l    31416923
  1086.  dc.l    12933933
  1087.  dc.l    413123213
  1088.  dc.l    122334412
  1089.  dc.l    112342213
  1090.  dc.l    66666333
  1091.  dc.l    123123
  1092.  dc.l    9387432
  1093.  dc.l    1128765
  1094.  dc.l    44982379
  1095.  dc.l    8768776
  1096.  dc.l    823277324
  1097.  dc.l    41234333
  1098.  dc.l    981744
  1099.  dc.l    12321071
  1100.  dc.l    279879
  1101.  dc.l    123219798
  1102.  dc.l    987923423
  1103.  dc.l    2346546
  1104.  dc.l    87171
  1105.  dc.l    244564537
  1106.  dc.l    6464564564
  1107.  dc.l    98898888
  1108.  dc.l    6262621313
  1109.  dc.l    989954654
  1110.  dc.l    39879879799
  1111.  dc.l    798797979
  1112.  dc.l    87686868
  1113.  dc.l    98797987987
  1114.  dc.l    998798879
  1115.  dc.l    43242432
  1116.  dc.l    37777777
  1117.  dc.l    9879745656
  1118.  dc.l    98798798
  1119.  dc.l    838383838
  1120.  dc.l    123123333
  1121.  dc.l    912387432
  1122.  dc.l    3123128765
  1123.  dc.l    987945645
  1124.  dc.l    8768776
  1125.  dc.l    82232433
  1126.  dc.l    9871234
  1127.  dc.l    9817444653
  1128.  dc.l    09871456
  1129.  dc.l    98797987987
  1130.  dc.l    998798879
  1131.  dc.l    43242432
  1132.  dc.l    123123
  1133.  dc.l    12312
  1134.  dc.l    1
  1135.  dc.l    12321
  1136.  dc.l    3
  1137.  dc.l    3333
  1138.  
  1139. * Fungis Timeout Timer 
  1140. fungis_timer    dc.w    0
  1141. test_fungis    dc.w    0
  1142.